/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * enregistrer.java
 *
 * Created on 21 janv. 2012, 13:16:20
 */
package bdlocale;

/**
 *
 * @author Marouane
 */
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.*;
import java.util.*;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class enregistrer extends javax.swing.JFrame {
 static SimplePalyer simpleplayer;
 fenetre4 f4 = new fenetre4();
    /** Creates new form enregistrer */
    public enregistrer() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jb1 = new javax.swing.ButtonGroup();
        jrr2 = new javax.swing.JRadioButton();
        jLabel1 = new javax.swing.JLabel();
        jrr1 = new javax.swing.JRadioButton();
        jp1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jl1 = new javax.swing.JList();
        jButton1 = new javax.swing.JButton();
        jp2 = new javax.swing.JPanel();
        t1 = new javax.swing.JTextField();
        jButton3 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBounds(new java.awt.Rectangle(450, 100, 400, 50));
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jrr2.setText("Ajouter une vidéo");
        jrr2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrr2ActionPerformed(evt);
            }
        });

        jLabel1.setText("Choissisez l'action à faire :");

        jrr1.setText("ouvrir une vidéo");
        jrr1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrr1ActionPerformed(evt);
            }
        });

        jl1.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                jl1ValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(jl1);

        jButton1.setText("Ouvrir");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jp1Layout = new javax.swing.GroupLayout(jp1);
        jp1.setLayout(jp1Layout);
        jp1Layout.setHorizontalGroup(
            jp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jp1Layout.createSequentialGroup()
                .addContainerGap(163, Short.MAX_VALUE)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(143, 143, 143))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jp1Layout.createSequentialGroup()
                .addGap(117, 117, 117)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE)
                .addGap(43, 43, 43))
        );
        jp1Layout.setVerticalGroup(
            jp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jp1Layout.createSequentialGroup()
                .addContainerGap(12, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1))
        );

        jButton3.setText("Enregistrer");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jp2Layout = new javax.swing.GroupLayout(jp2);
        jp2.setLayout(jp2Layout);
        jp2Layout.setHorizontalGroup(
            jp2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp2Layout.createSequentialGroup()
                .addGroup(jp2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jp2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(t1, javax.swing.GroupLayout.DEFAULT_SIZE, 211, Short.MAX_VALUE))
                    .addGroup(jp2Layout.createSequentialGroup()
                        .addGap(70, 70, 70)
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jp2Layout.setVerticalGroup(
            jp2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jp2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(t1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton3)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addContainerGap(383, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(98, 98, 98)
                .addComponent(jrr1)
                .addGap(50, 50, 50)
                .addComponent(jrr2)
                .addGap(115, 115, 115))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(153, Short.MAX_VALUE)
                .addComponent(jp2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(135, 135, 135))
            .addGroup(layout.createSequentialGroup()
                .addGap(38, 38, 38)
                .addComponent(jp1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(87, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(42, 42, 42)
                .addComponent(jLabel1)
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jrr1)
                    .addComponent(jrr2))
                .addGap(18, 18, 18)
                .addComponent(jp1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(34, 34, 34)
                .addComponent(jp2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    try {
       
    Connection c = BDlocale.createConnection();
    Statement st = c.createStatement();
    if(jrr1.isEnabled()){
       String cc = jl1.getSelectedValue().toString();
    //  System.out.print(cc);
       f4.show();
  //f4.setBounds(50, 10, 1300, 730);
  

            
          
          ResultSet rs = st.executeQuery("select pathv from video where pathv = '"+cc+"'");
          
             while (rs.next()) {
                 String dd = rs.getString(1);
            //URL ddd = (URL)dd;
               URL j = new URL(dd);
              
               
              // URL sss = rs.getURL("pathv"); 

               simpleplayer = new SimplePalyer("Match Rugby",j);
	       simpleplayer.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
               simpleplayer.setBounds(310,100, 1050, 400);
               simpleplayer.setAlwaysOnTop(true);
               simpleplayer.setUndecorated(true);//pour enlever les boutton de la frame
               simpleplayer.setResizable(false);
             // simpleplayer.
              //fenetre3.simpleplayer.getContentPane().add(this);
              simpleplayer.setVisible(true);
             
              this.dispose();
  
	       }     
             
             
   
      }
     
          }catch(Exception ex){
        JOptionPane.showMessageDialog(null,"veuillez sélectionnez un élément dans la liste");
    }  
      
      
}//GEN-LAST:event_jButton1ActionPerformed

private void jl1ValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jl1ValueChanged
// TODO add your handling code here:
}//GEN-LAST:event_jl1ValueChanged

private void jrr2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrr2ActionPerformed

    jb1.add(jrr2);
 jrr2.setSelected(true);
 jrr2.setEnabled(true);
 jp1.setVisible(false);
 jp2.setVisible(true);
 //t1.setText("");
 
 //jrr1.setEnabled(false);
   JFileChooser chooser = new JFileChooser();

		int option = chooser.showOpenDialog(null);
		if(option == JFileChooser.APPROVE_OPTION) {
			try {

				
				URL url = chooser.getSelectedFile().toURL();
                                t1.setText(url.toString());
				
				
			}catch(MalformedURLException ex){
				System.out.println("The url was malformed");}}
}//GEN-LAST:event_jrr2ActionPerformed

private void jrr1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrr1ActionPerformed
jb1.add(jrr1);

 jrr1.setSelected(true);
 jrr1.setEnabled(true);
 jp2.setVisible(false);
 jp1.setVisible(true);

  //  jrr2.setEnabled(false);
  try {
            
          Connection c = BDlocale.createConnection();
          Statement st = c.createStatement();
          ResultSet rs = st.executeQuery("select pathv from video");
          Vector tab = new Vector();
          Vector tab1 = new Vector();

             while (rs.next()) {
              
              tab.add(rs.getString("pathv"));
              
                jl1.setListData(tab);
	       }
          /* ResultSet rs1 = st.executeQuery("select num_joueur from joueur");
          
             while (rs1.next()) {
                 
                tab1.add(rs1.getString("num_joueur"));
                jl.setListData(tab1);
                
	       }*/
             
             
            
        } catch (Exception ex) {
            ex.printStackTrace();        }
  
    

 
}//GEN-LAST:event_jrr1ActionPerformed

private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
jb1.add(jrr1);
    jrr1.setSelected(true);
    jp2.setVisible(false);
  //  jrr2.setEnabled(false);
    this.setResizable(false);
    
  try {
            
          Connection c = BDlocale.createConnection();
          Statement st = c.createStatement();
          ResultSet rs = st.executeQuery("select pathv from video");
          Vector tab = new Vector();
          Vector tab1 = new Vector();

             while (rs.next()) {
              
              tab.add(rs.getString("pathv"));
              
                jl1.setListData(tab);
	       }
          /* ResultSet rs1 = st.executeQuery("select num_joueur from joueur");
          
             while (rs1.next()) {
                 
                tab1.add(rs1.getString("num_joueur"));
                jl.setListData(tab1);
                
	       }*/
            
             this.setBounds(200, 100, 500, 300);
            
        } catch (Exception ex) {
            ex.printStackTrace();        }
  
   

}//GEN-LAST:event_formWindowOpened

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
try {
    Connection c = BDlocale.createConnection();
    Statement st = c.createStatement();
    Statement stt = c.createStatement();
         st.executeUpdate("insert into video (pathv) values ('"+t1.getText()+"')");
        //  this.dispose();
        t1.setText("");
        JOptionPane.showMessageDialog(null,"ajout avec succès");
    
    
        
          }catch(Exception ex){
        ex.printStackTrace();
    }  
}//GEN-LAST:event_jButton3ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(enregistrer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(enregistrer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(enregistrer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(enregistrer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new enregistrer().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.ButtonGroup jb1;
    private javax.swing.JList jl1;
    private javax.swing.JPanel jp1;
    private javax.swing.JPanel jp2;
    private javax.swing.JRadioButton jrr1;
    private javax.swing.JRadioButton jrr2;
    private javax.swing.JTextField t1;
    // End of variables declaration//GEN-END:variables
}
